class Solution(object):
    def numFactoredBinaryTrees(self, arr):
        base = 10 ** 9 + 7
        arr.sort()
        n = len(arr)
        d = {arr[i]: i for i in range(n)}
        DP = [1] * n
        for i in range(n):
            for j in range(i):
                if arr[i] % arr[j] == 0:
                    value = arr[i] // arr[j]
                    if value in d:
                        DP[i] = (DP[i] + DP[j] * DP[d[value]]) % base
        return sum(DP) % base



data = Solution()
arr = [2, 4, 5, 10, 20]
print(data.numFactoredBinaryTrees(arr))